kern/misc: Add sanity check after grub_strtoul() call
authorLidong Chen <lidong.chen@oracle.com>
Thu, 6 Feb 2025 18:16:57 +0000 (18:16 +0000)
committerFelix Zielcke <fzielcke@z-51.de>
Thu, 3 Jul 2025 16:35:51 +0000 (18:35 +0200)
commit2a8128bf0caea108d695a829b7c7b6b18f72713c
tree1176784fc74abcbc1e3a184c9a127bdf10e7ed8a
parent9959825118c84c32d27a0fb030dc52cda1101dfe
kern/misc: Add sanity check after grub_strtoul() call

When the format string, fmt0, includes a positional argument
grub_strtoul() or grub_strtoull() is called to extract the argument
position. However, the returned argument position isn't fully validated.
If the format is something like "%0$x" then these functions return
0 which leads to an underflow in the calculation of the args index, curn.
The fix is to add a check to ensure the extracted argument position is
greater than 0 before computing curn. Additionally, replace one
grub_strtoull() with grub_strtoul() and change curn type to make code
more correct.

Fixes: CID 473841
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Gbp-Pq: Topic cve-2025-jan
Gbp-Pq: Name kern-misc-Add-sanity-check-after-grub_strtoul-call.patch
grub-core/kern/misc.c